package com.spodrum.balloon;

import java.util.Random;

import android.graphics.Color;

public class Particle 
{
	public int distFromOrigin = 0;
	private double direction;
	private double directionCosine;
	private double directionSine;
	public int image;
	public int x;
	public int y;
	private int initX;
	private int initY;
	private int timeToLive = 10000;
	private long now, previousTime, elapsedTime, deltaTime;
	
	private float ratio;
	private boolean alive;
	private int colour;
	public int alpha = 255;

		
	public Particle(int x, int y) {
		init(x, y);
		this.direction = 2*Math.PI * new Random().nextInt(NO_OF_DIRECTION)/NO_OF_DIRECTION;
		this.directionCosine = Math.cos(direction);
		this.directionSine = Math.sin(direction);
		this.image = new Random().nextInt(3);
		this.colour = Color.BLUE;
	}
	
	public void init(int x, int y) 
	{
		distFromOrigin = 0;
		this.initX = this.x = x;
		this.initY = this.y = y;
		now = 0;
		previousTime = 0;
		elapsedTime = 0;
		deltaTime = 0;
		alpha = 255;
		
	}

	public void move()
	{
		now = System.currentTimeMillis();
		
		if(previousTime != 0)
			deltaTime = now - previousTime;
		
		elapsedTime += deltaTime;
		
		if(elapsedTime > timeToLive)
			setAlive(false);

		//size = ( (timeToLive - elapsedTime) / timeToLive) * size;
		//size = size - (elapsedTime/timeToLive)*size;
		//alpha = (int) (alpha - (elapsedTime/timeToLive)*alpha);
		ratio = (float) elapsedTime/(float) timeToLive * alpha;
		alpha = (int) (alpha - ratio);
		
		System.out.println("Alpha:" + alpha);
		
		distFromOrigin +=2;
		x = (int) (initX+distFromOrigin*directionCosine);
		y = (int) (initY+distFromOrigin*directionSine);
		
		previousTime = now;
	}
	
	
	public int getColour() {
		return colour;
	}

	public void setColour(int colour) {
		this.colour = colour;
	}

	public boolean isAlive() {
		return alive;
	}

	public void setAlive(boolean alive) {
		this.alive = alive;
	}


	private final static int NO_OF_DIRECTION = 400; 

}